package wxy.studentmanage.handler;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import wxy.studentmanage.bean.Users;
import wxy.studentmanage.mapper.UserMapper;
import wxy.studentmanage.service.UserService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/user")
public class loginController {
    @Autowired
    @Qualifier("UserServiceImpl")
    private UserService userService;


    @RequestMapping("/main")
    public String main(){
        return "redirect:/allUsers/allUser";
    }
    //进入欢迎页
    @RequestMapping("/index")
    public String index(){
        return "index";
    }
    //进入登录页
    @RequestMapping("/toLogin")
    public String toLogin(){
        return "login";
    }
    @RequestMapping("/login")
    public String login(HttpSession session, @RequestParam String wxy_username, @RequestParam String wxy_password){
        System.out.println(wxy_username+wxy_password);
        session.setAttribute("user",wxy_username);
        //model.addAttribute("username",wxy_username);
        Users users = userService.login(wxy_username,wxy_password);
        System.out.println(users);
        if (users != null){
            return "redirect:/allUsers/allUser";
        }
        return "error";



        //        Users users = userService.login(wxy_username,wxy_password);
//        if (null != users){
//            //return "redirect:"
//            return "main";
//        }
//        return "login";
    }
    @RequestMapping("/goOut")
    public String goOut(HttpSession session){
        //存用户的信息
        session.removeAttribute("user");
        return "index";
    }




//    //
//    @RequestMapping("/main")
//    public String main(){
//        return "redirect:/user/allUser";
//    }
//
//    //进入登录页
//
//    @RequestMapping(value = "login/welcome",method = RequestMethod.GET)
//    public String welcome(){
//        return "index";
//    }
//    //进入登录页
//
//    @RequestMapping(value = "login/index",method = RequestMethod.GET)
//    public String index(){
//        return "login";
//    }
//    //进入首页
//    @RequestMapping("/allUser")
////    public String allUser(Model model, Users users,HttpSession session){
////        System.out.println("11111"+users.getWxy_username());
////        session.setAttribute("wxy_username",users.getWxy_username());
////        List<Users> list = userService.queryAllUser();
////        model.addAttribute("list", list);
////        System.out.println(list);
////        System.out.println(list);
////        return "allUser";
////    }
//
//    @RequestMapping("/goOut")
//    public String goOut(HttpSession session){
//        //销毁用户的信息
//        session.removeAttribute("wxy_username");
//        return "index";
//    }
//
//
//
//
//
//






}
